/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.Arrays;

/**
 *
 * @author ian
 */
public class ReportControl {
    private double[] data;

    public ReportControl(double[] data) {
        this.data = data;
    }
    

    public double[] CentralTendency() {
        
        //Media
        double[] res = new double[3];
        double sum = 0.0;
        for (int i = 0; i < data.length; i++) {
            sum += data[i];
        }
        res[0] = sum / data.length;
        
        //Moda
        int maxrepeated = 0;
        double moda = 0;
        for (int i = 0; i < data.length; i++) {
            int timesrepeated = 0;
            for (int j = 0; j < data.length; j++) {
                if (data[i] == data[j]) {
                    timesrepeated++;
                }
            }
            if (timesrepeated > maxrepeated) {
                moda = data[i];
                maxrepeated = timesrepeated;
            }
        }
        res[1] = moda;
        
        //Mediana
        Arrays.sort(data);
        if (data.length%2 == 0){
            int mid = (data.length+1)/2;
            res[2] = (data[mid]+(data[mid-1]))/2;
        }
        else{
            int mid = (data.length)/2;
            res[2] = data[mid];
        }

        return res;
    }
    
    public double[] StatisticalDispersion(){
        
        //Varianza
        double mean = CentralTendency()[0];
        double[] res = new double[3];
        double sum2 = 0.0;
        for (int i = 0; i < data.length; i++) {
            sum2 += data[i]*data[i];
        }
        res[0] = (sum2/(data.length))-(mean*mean);
        
        //Desviacion Estandar
        res[1] = Math.sqrt(res[0]);
        
        //Rango Intercuartilico
        
        
        return res;
    }
    
}